package com.GUIWork;

import javax.swing.JFrame;

import com.dbConnection.theConnection;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.sql.SQLException;

import javax.swing.JLabel;

public class ratingPage extends JFrame {
	
	theConnection conn;
	Integer itemid;
	
	public ratingPage(theConnection conn, int itemid){
		this.conn = conn;
		this.itemid = itemid;
		setTitle("Item ID: "+ this.itemid.toString());
		
		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel itemName = new JLabel("");
		itemName.setBounds(10, 29, 127, 14);
		try{
			conn.askDB("SELECT Name FROM Item WHERE ItemID = " + this.itemid.toString());
			itemName.setText("Item Name: " + conn.getLastQuery(1).get(0));
		} catch(Exception e){
			System.out.println("Item Not Found");
			e.printStackTrace();
		}
		panel.add(itemName);
		
		JLabel avgRating = new JLabel("");
		avgRating.setBounds(10, 54, 151, 14);
		try{
			conn.askDB("SELECT AVG(Stars) FROM Rates WHERE ItemID = " + this.itemid.toString());
			avgRating.setText("Average Rating: " + conn.getLastQuery(1).get(0) + " Stars");
		}catch(Exception e){}
		panel.add(avgRating);
		
		
	}
	
}
